<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="mainDebtModel" :rules="validatorRules">

        <!-- 主表单区域 -->
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customId" label="客户ID">
          <a-input placeholder="请输入客户ID" v-model="mainDebtModel.customId"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customName" label="客户名称">
          <a-input placeholder="请输入客户名称" v-model="mainDebtModel.customName"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerType" label="客户性质">
          <a-input placeholder="请输入客户性质" v-model="mainDebtModel.customerType"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="debtDay" label="欠款天数">
          <a-input placeholder="请输入欠款天数" v-model="mainDebtModel.debtDay"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settleType" label="结算方式">
          <a-input placeholder="请输入结算方式" v-model="mainDebtModel.settleType"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zxArea" label="区域">
          <a-input placeholder="请输入区域" v-model="mainDebtModel.zxArea"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tranPosName" label="运输线路">
          <a-input placeholder="请输入运输线路" v-model="mainDebtModel.tranPosName"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalDebt" label="未付款总额">
          <a-input placeholder="请输入未付款总额" v-model="mainDebtModel.totalDebt"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalRefund" label="代付款总额">
          <a-input placeholder="请输入代付款总额" v-model="mainDebtModel.totalRefund"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesmanId" label="业务员ID">
          <a-input placeholder="请输入业务员ID" v-model="mainDebtModel.salesmanId"/>
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesman" label="业务员名称">
          <a-input placeholder="请输入业务员名称" v-model="mainDebtModel.salesman"/>
        </a-form-model-item>

      </a-form-model>
    </a-spin>
  </a-modal>

</template>

<script>
  import { httpAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  import DetailDebtCustomerList from '../DetailDebtCustomerList'

  export default {
    name: 'MainDebtCustomerModal',
    components: {
      JDate
    },
    data() {
      return {
        title: '操作',
        visible: false,
        mainDebtModel: {
          detailDebtCustomerList: [{}],
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          customId: [
            { required: true, message: '请输入业务员ID!' }
          ]
        },
        url: {
          add: '/inca/bmsSalesman/add',
          edit: '/inca/bmsSalesman/edit',
          detailDebtCustomerList: '/inca/debtCustomer/getListByMainId',
          //orderTicketList: '/test/order/listOrderTicketByMainId',
        },
      }
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.mainDebtModel = Object.assign({}, record)
        console.log(this.mainDebtModel)
        //初始化明细表数据
        this.visible = true
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.$refs.form.resetFields()
      },
      handleOk() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.mainDebtModel.id) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'put'
            }

            httpAction(httpurl, this.mainDebtModel, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.confirmLoading = false
              that.close()
            })
          } else {
            return false
          }
        })
      },
      handleCancel() {
        this.close()
      }
    }
  }
</script>

<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }

  .ant-form-item-control {
    line-height: 0px;
  }

  /** 主表单行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }

  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }
</style>